<template>
	<el-main class="bg">
		<el-form ref="form" :model="form" status-icon label-width="120px" v-if="is_view()">
			<el-col
				v-if="user_group === '管理员' || $check_field('get', 'event_number') || $check_field('add', 'event_number') || $check_field('set', 'event_number')"
				:xs="24" :sm="12" :lg="8">
				<el-form-item label="赛事编号" prop="event_number">
					<el-input id="event_number" v-model="form['event_number']" placeholder="请输入赛事编号"
						v-if="user_group === '管理员' || (form['budget_application_id'] && $check_field('set', 'event_number')) || (!form['budget_application_id'] && $check_field('add', 'event_number'))"
						:disabled="disabledObj['event_number_isDisabled']"></el-input>
					<div v-else-if="$check_field('get', 'event_number')">{{ form['event_number'] }}</div>
				</el-form-item>
			</el-col>
			<el-col
				v-if="user_group === '管理员' || $check_field('get', 'entry_name') || $check_field('add', 'entry_name') || $check_field('set', 'entry_name')"
				:xs="24" :sm="12" :lg="8">
				<el-form-item label="赛事名称" prop="entry_name">
					<el-select id="entry_name" v-model="form['entry_name']" placeholder="请选择赛事名称" v-if="user_group === '管理员'"
						:disabled="disabledObj['entry_name_isDisabled']" @change="fillEventInfo">
						<el-option v-for="(name, index) in eventList" :key="index" :label="name" :value="name"></el-option>
					</el-select>
					<div v-else-if="$check_field('get', 'entry_name')">{{ form['entry_name'] }}</div>
				</el-form-item>
			</el-col>
			<el-col
				v-if="user_group === '管理员' || $check_field('get', 'registration_fee') || $check_field('add', 'registration_fee') || $check_field('set', 'registration_fee')"
				:xs="24" :sm="12" :lg="8">
				<el-form-item label="参赛注册费" prop="registration_fee">
					<el-input id="registration_fee" v-model="form['registration_fee']" placeholder="请输入参赛注册费"
						v-if="user_group === '管理员' || (form['budget_application_id'] && $check_field('set', 'registration_fee')) || (!form['budget_application_id'] && $check_field('add', 'registration_fee'))"
						:disabled="disabledObj['registration_fee_isDisabled']"></el-input>
					<div v-else-if="$check_field('get', 'registration_fee')">{{ form['registration_fee'] }}</div>
				</el-form-item>
			</el-col>
			<!-- <el-col
				v-if="user_group === '管理员' || $check_field('get', 'rate_difference_fee') || $check_field('add', 'rate_difference_fee') || $check_field('set', 'rate_difference_fee')"
				:xs="24" :sm="12" :lg="8">
				<el-form-item label="差率费" prop="rate_difference_fee">
					<el-input id="rate_difference_fee" v-model="form['rate_difference_fee']" placeholder="请输入差率费"
						v-if="user_group === '管理员' || (form['budget_application_id'] && $check_field('set', 'rate_difference_fee')) || (!form['budget_application_id'] && $check_field('add', 'rate_difference_fee'))"
						:disabled="disabledObj['rate_difference_fee_isDisabled']"></el-input>
					<div v-else-if="$check_field('get', 'rate_difference_fee')">{{ form['rate_difference_fee'] }}</div>
				</el-form-item>
			</el-col> -->
			<!-- <el-col
				v-if="user_group === '管理员' || $check_field('get', 'training_fee') || $check_field('add', 'training_fee') || $check_field('set', 'training_fee')"
				:xs="24" :sm="12" :lg="8">
				<el-form-item label="培训费" prop="training_fee">
					<el-input id="training_fee" v-model="form['training_fee']" placeholder="请输入培训费"
						v-if="user_group === '管理员' || (form['budget_application_id'] && $check_field('set', 'training_fee')) || (!form['budget_application_id'] && $check_field('add', 'training_fee'))"
						:disabled="disabledObj['training_fee_isDisabled']"></el-input>
					<div v-else-if="$check_field('get', 'training_fee')">{{ form['training_fee'] }}</div>
				</el-form-item>
			</el-col>
			<el-col
				v-if="user_group === '管理员' || $check_field('get', 'guidance_fee') || $check_field('add', 'guidance_fee') || $check_field('set', 'guidance_fee')"
				:xs="24" :sm="12" :lg="8">
				<el-form-item label="指导费" prop="guidance_fee">
					<el-input id="guidance_fee" v-model="form['guidance_fee']" placeholder="请输入指导费"
						v-if="user_group === '管理员' || (form['budget_application_id'] && $check_field('set', 'guidance_fee')) || (!form['budget_application_id'] && $check_field('add', 'guidance_fee'))"
						:disabled="disabledObj['guidance_fee_isDisabled']"></el-input>
					<div v-else-if="$check_field('get', 'guidance_fee')">{{ form['guidance_fee'] }}</div>
				</el-form-item>
			</el-col> -->
			<el-col
				v-if="user_group === '管理员' || $check_field('get', 'consumables') || $check_field('add', 'consumables') || $check_field('set', 'consumables')"
				:xs="24" :sm="12" :lg="8">
				<el-form-item label="耗材费" prop="consumables">
					<el-input id="consumables" v-model="form['consumables']" placeholder="请输入耗材费"
						v-if="user_group === '管理员' || (form['budget_application_id'] && $check_field('set', 'consumables')) || (!form['budget_application_id'] && $check_field('add', 'consumables'))"
						:disabled="disabledObj['consumables_isDisabled']"></el-input>
					<div v-else-if="$check_field('get', 'consumables')">{{ form['consumables'] }}</div>
				</el-form-item>
			</el-col>
			<el-col
				v-if="user_group === '管理员' || $check_field('get', 'teacher_bonus') || $check_field('add', 'teacher_bonus') || $check_field('set', 'teacher_bonus')"
				:xs="24" :sm="12" :lg="8">
				<el-form-item label="教师奖金" prop="teacher_bonus">
					<el-input id="teacher_bonus" v-model="form['teacher_bonus']" placeholder="请输入教师奖金"
						v-if="user_group === '管理员' || (form['budget_application_id'] && $check_field('set', 'teacher_bonus')) || (!form['budget_application_id'] && $check_field('add', 'teacher_bonus'))"
						:disabled="disabledObj['teacher_bonus_isDisabled']"></el-input>
					<div v-else-if="$check_field('get', 'teacher_bonus')">{{ form['teacher_bonus'] }}</div>
				</el-form-item>
			</el-col>
			<el-col
				v-if="user_group === '管理员' || $check_field('get', 'other') || $check_field('add', 'other') || $check_field('set', 'other')"
				:xs="24" :sm="12" :lg="8">
				<el-form-item label="其他" prop="other">
					<el-input id="other" v-model="form['other']" placeholder="请输入其他"
						v-if="user_group === '管理员' || (form['budget_application_id'] && $check_field('set', 'other')) || (!form['budget_application_id'] && $check_field('add', 'other'))"
						:disabled="disabledObj['other_isDisabled']"></el-input>
					<div v-else-if="$check_field('get', 'other')">{{ form['other'] }}</div>
				</el-form-item>
			</el-col>
			<el-col :xs="24" :sm="12" :lg="8">
				<el-form-item label="审核状态" prop="examine_state">
					<el-select id="examine_state" v-model="form['examine_state']"
						v-if="user_group === '管理员' || (form['examine_state'] && $check_examine()) || (!form['examine_state'] && $check_examine())">
						<el-option key="未审核" label="未审核" value="未审核"></el-option>
						<el-option key="已通过" label="已通过" value="已通过"></el-option>
						<el-option key="未通过" label="未通过" value="未通过"></el-option>
					</el-select>
					<div v-else-if="$check_field('get', 'examine_state')">{{ form["examine_state"] }}</div>
				</el-form-item>
			</el-col>
			<el-col :xs="24" :sm="12" :lg="8">
				<el-form-item>
					<el-button type="primary" @click="submit()">提交</el-button>
					<el-button @click="cancel()">取消</el-button>
				</el-form-item>
			</el-col>

		</el-form>
	</el-main>
</template>

<script>
import mixin from "@/mixins/page.js";

export default {
	mixins: [mixin],
	data() {
		return {
			field: "budget_application_id",
			url_add: "~/api/budget_application/add?",
			url_set: "~/api/budget_application/set?",
			url_get_obj: "~/api/budget_application/get_obj?",
			url_upload: "~/api/budget_application/upload?",

			query: {
				"budget_application_id": 0,
			},

			form: {
				"event_number": '', // 赛事编号
				"entry_name": '', // 参赛名称
				"registration_fee": '', // 参赛注册费
				"rate_difference_fee": '', // 差率费
				"training_fee": '', // 培训费
				"guidance_fee": '', // 指导费
				"consumables": '', // 耗材费
				"teacher_bonus": '', // 教师奖金
				"other": '', // 其他
				"examine_state": "未审核",
				"budget_application_id": 0, // ID

			},
			disabledObj: {
				"event_number_isDisabled": false,
				"entry_name_isDisabled": false,
				"registration_fee_isDisabled": false,
				"rate_difference_fee_isDisabled": false,
				"training_fee_isDisabled": false,
				"guidance_fee_isDisabled": false,
				"consumables_isDisabled": false,
				"teacher_bonus_isDisabled": false,
				"other_isDisabled": false,
			},

			eventList: [],
			fullEventList: [],

		}
	},
	created() {
		this.get_event_type();
	},
	methods: {
		//获取赛事类型
		async get_event_type() {
			var json = await this.$get("~/api/event_application/get_list?like=0");
			console.log(json.result.list);
			this.fullEventList = [];
			if (json.result && json.result.list) {
				json.result.list.forEach(item => {
					if (item.examine_state === "已通过") {
						this.eventList.push(item.event_name);
						this.fullEventList.push(item);
					}
				});
			}
			else if (json.error) {
				console.error(json.error);
			}
		},
		// 填充赛事类型和赛事编号
		fillEventInfo() {
			const selectedEvent = this.fullEventList.find(item => item.event_name === this.form['entry_name']);
			if (selectedEvent) {
				// this.form['event_type'] = selectedEvent.event_type;
				this.form['event_number'] = selectedEvent.event_number;
			} else {
				this.form['event_type'] = '';
				this.form['event_number'] = '';
			}
		},

		/**
		 * 获取对象之前
		 * @param {Object} param
		 */
		get_obj_before(param) {
			var form = "";
			if (this.form && form) {
				Object.keys(this.form).forEach(key => {
					Object.keys(form).forEach(dbKey => {
						// if(dbKey === "charging_standard"){
						// 	this.form['charging_rules'] = form[dbKey];
						// 	this.disabledObj['charging_rules_isDisabled'] = true;
						// };
						if (key === dbKey) {
							this.disabledObj[key + '_isDisabled'] = true;
						}
					})
				})
			}
			$.db.del("form");
			return param;
		},

		/**
		 * 获取对象之后
		 * @param {Object} json
		 * @param {Object} func
		 */
		get_obj_after(json, func) {

		},

		is_view() {
			var bl = this.user_group == "管理员";

			if (!bl) {
				bl = this.$check_action('/budget_application/table', 'add');
				console.log(bl ? "你有表格添加权限视作有添加权限" : "你没有表格添加权限");
			}
			if (!bl) {
				bl = this.$check_action('/budget_application/table', 'set');
				console.log(bl ? "你有表格添加权限视作有修改权限" : "你没有表格修改权限");
			}
			if (!bl) {
				bl = this.$check_action('/budget_application/view', 'add');
				console.log(bl ? "你有视图添加权限视作有添加权限" : "你没有视图添加权限");
			}
			if (!bl) {
				bl = this.$check_action('/budget_application/view', 'set');
				console.log(bl ? "你有视图修改权限视作有修改权限" : "你没有视图修改权限");
			}
			if (!bl) {
				bl = this.$check_action('/budget_application/view', 'get');
				console.log(bl ? "你有视图查询权限视作有查询权限" : "你没有视图查询权限");
			}

			console.log(bl ? "具有当前页面的查看权，请注意这不代表你有字段的查看权" : "无权查看当前页，请注意即便有字段查询权限没有页面查询权限也不行");

			return bl;
		},
		/**
		 * 上传文件
		 * @param {Object} param
		 */
		uploadimg(param) {
			this.uploadFile(param.file, "avatar");
		},

	},
}
</script>

<style>
.avatar-uploader .el-upload {
	border: 1px dashed #d9d9d9;
	border-radius: 6px;
	cursor: pointer;
	position: relative;
	overflow: hidden;
}

.avatar-uploader .el-upload:hover {
	border-color: #409EFF;
}

.avatar-uploader-icon {
	font-size: 28px;
	color: #8c939d;
	width: 178px;
	height: 178px;
	line-height: 178px;
	text-align: center;
}

.avatar {
	width: 178px;
	height: 178px;
	display: block;
}
</style>
